#include "user.h"
#include "ui_user.h"
#include <entity/userentity.h>
#include <dbmanager.h>

User::User(QWidget *parent) :
    QWidget(parent), ui(new Ui::User)
{
    ui->setupUi(this);
    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
    connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearClicked()));
}

User::~User()
{
    delete ui;
}

void User::okClicked()
{
    UserEntity * user = new UserEntity();
    user->setName(ui->nameText->text());
    user->setAddress(ui->addrText->text());
    user->setCity(ui->cityText->text());
    user->setNicNo(ui->phoneText->text());
    user->setPhone(ui->phoneText->text());
    user->setJoinedDate(ui->joinDateText->text());
    user->setPerm(ui->permCombo->currentIndex());
    user->setUsername(ui->usernameText->text());
    user->setPassword(ui->passwordText->text());
    user->setDeleted(0);

    DBManager * dbm = DBManager::getGlobal();
    dbm->insertUser(user);

    delete user;
}

void User::clearClicked()
{

}
